package com.ruoyi.web.controller.manualDiscountRules;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ManualDiscountConfig;
import com.ruoyi.system.service.IManualDiscountConfigService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 手动优惠规则配置 Controller
 *
 * @author ruoyi
 * @date 2025-05-16
 */
@Api(tags="手动优惠规则配置")
@RestController
@RequestMapping("/system/manualDiscountConfig")
public class ManualDiscountConfigController extends BaseController
{
    @Autowired
    private IManualDiscountConfigService manualDiscountConfigService;

    /**
     * 通过规则名称查询手动优惠规则配置列表
     */
    @ApiOperation("通过规则名称查询手动优惠规则配置列表")
    @PreAuthorize("@ss.hasPermi('system:config:list')")
    @GetMapping("/list")
    public TableDataInfo list(@RequestParam (required = false) String ruleName)
    {
        startPage();
        List<ManualDiscountConfig> list = manualDiscountConfigService.selectManualDiscountConfigListByName(ruleName);
        return getDataTable(list);
    }

    /**
     * 导出手动优惠规则配置列表
     */
    @ApiOperation("导出手动优惠规则配置列表")
    @PreAuthorize("@ss.hasPermi('system:config:export')")
    @Log(title = "手动优惠规则配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestParam (required = false) String ruleName)
    {
        List<ManualDiscountConfig> list = manualDiscountConfigService.selectManualDiscountConfigListByName(ruleName);
        ExcelUtil<ManualDiscountConfig> util = new ExcelUtil<ManualDiscountConfig>(ManualDiscountConfig.class);
        util.exportExcel(response, list, "手动优惠规则配置数据");
    }

    /**
     * 通过id获取手动优惠规则配置详细信息
     */
    @ApiOperation("通过id获取手动优惠规则配置详细信息")
    @PreAuthorize("@ss.hasPermi('system:config:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(manualDiscountConfigService.selectManualDiscountConfigById(id));
    }

    /**
     * 新增手动优惠规则配置
     */
    @ApiOperation("新增手动优惠规则配置")
    @PreAuthorize("@ss.hasPermi('system:config:add')")
    @Log(title = "手动优惠规则配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ManualDiscountConfig manualDiscountConfig)
    {
        return toAjax(manualDiscountConfigService.insertManualDiscountConfig(manualDiscountConfig));
    }

    /**
     * 修改手动优惠规则配置
     */
    @ApiOperation("修改手动优惠规则配置")
    @PreAuthorize("@ss.hasPermi('system:config:edit')")
    @Log(title = "手动优惠规则配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ManualDiscountConfig manualDiscountConfig)
    {
        return toAjax(manualDiscountConfigService.updateManualDiscountConfig(manualDiscountConfig));
    }

    /**
     * 通过id批量删除手动优惠规则配置信息
     */
    @ApiOperation("通过id批量删除手动优惠规则配置信息")
    @PreAuthorize("@ss.hasPermi('system:config:remove')")
    @Log(title = "手动优惠规则配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(manualDiscountConfigService.deleteManualDiscountConfigByIds(ids));
    }
}

